package com.example.onlineeducation.mapper

import com.example.onlineeducation.data.constant.OfflineStudyLiveState
import com.example.onlineeducation.data.entity.OfflineStudyLiveDetailEntity
import com.example.onlineeducation.data.json.OfflineStudyLiveDetailJson
import com.example.onlineeducation.utils.YcTimeUtils
import com.yc.jetpacklib.data.constant.YcNetErrorCode
import com.yc.jetpacklib.exception.YcException
import com.yc.jetpacklib.extension.ycToNoEmpty

import com.yc.jetpacklib.mapper.IMapper
import com.yc.jetpacklib.utils.YcTime

class OfflineStudyLiveDetailMapper : IMapper<OfflineStudyLiveDetailJson?, OfflineStudyLiveDetailEntity> {
    override fun map(input: OfflineStudyLiveDetailJson?): OfflineStudyLiveDetailEntity {
        return if (input != null) {
            val studyLiveState = OfflineStudyLiveState.getStudyLiveState(input.beginTime, input.endTime)
            val signState = OfflineStudyLiveState.getSignState(input.signInTime, input.signOutTime, input.endTime)
            OfflineStudyLiveDetailEntity(
                input.mediaInfo?.webPath,
                input.name.ycToNoEmpty(),
                YcTimeUtils.stringToString(input.beginTime, "-", YcTime.FORMAT_TIME_SECOND, "yyyy.MM.dd HH:mm"),
                YcTimeUtils.stringToString(input.endTime, "-", YcTime.FORMAT_TIME_SECOND, "yyyy.MM.dd HH:mm"),
                studyLiveState,
                OfflineStudyLiveState.getStudyLiveStateName(studyLiveState),
                input.content.ycToNoEmpty(),
                signState,
                OfflineStudyLiveState.getSignStateName(signState),
                input.address.ycToNoEmpty()
            )
        } else {
            throw YcException(YcNetErrorCode.DATE_NULL_ERROR, "活动详情数据为空异常")
        }
    }
}

